﻿@model WaiGaoQiaoWeb.Models.DepartMentVM

@{
    ViewBag.Title = "DepartMent";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
       @Html.Css("EditForm")
       <script type="text/javascript" language="javascript">
           var maiheight = document.documentElement.clientHeight;
           $(document).ready(function () {
               var option = {
                   url: '@Url.Action("GetAllDepartMent")',
                   showcheck: false,
                   onnodeclick: TreeNode_Click,
                   theme: "bbit-tree-no-lines" //bbit-tree-lines ,bbit-tree-no-lines,bbit-tree-arrows
               }
               $("#divdepart").height(maiheight - 29);
               $("form").makeValidationInline();
               //保存
               $("#btnSave").click(function (event) {
                   if (!$("#fmEdit").valid()) {
                       return false;
                   }
                   $('#fmEdit').ajaxSubmit(function (callback) {
                       if (callback) {
                           showLoadingMsg("保存成功", { left: 300, top: 6, width: 200 }, true, 3000);
                           $("#ptree").treeview(option).height(maiheight - 29);
                       }
                   });
               });
               $("#btnDel").click(function () {
                   if (!confirm("确定要删除此部门吗？")) {
                       return false;
                   }
                   var did = $("#Dep_ID").val();
                   var rowcount = 0;
                   $.ajax({
                       type: "POST",
                       url: '@Url.Action("DeleteDepartMent")',
                       data: { deptid: did },
                       dataType: "json",
                       async: false,
                       success: function (data) {
                           if (data) {
                               rowcount = rowcount + ((data == -1) ? 0 : data);
                               $("#ptree").treeview(option).height(maiheight - 29);
                           }
                       },
                       error: function () { }
                   });   // end of ajax  
                   $("input").val("");
                   showLoadingMsg("共有" + rowcount.toString() + "个部门被删除!", { left: 400, top: 6 }, true, 3000);
               });
               $("#ptree").treeview(option).height(maiheight - 29);
               $("#btnFind").click(function () {
                   var did = $("#Dep_ID").val();
                   if (!did) {
                       showLoadingMsg("请选择左边要查看的部门", { left: 400, top: 6 }, true, 3000);
                       return false;
                   }
                   $.ajax({
                       type: "POST",
                       url: '@Url.Action("GetOneDepartMent")',
                       data: { deptid: did },
                       dataType: "json",
                       success: function (data) {
                           if (data) {
                               $("#Dep_ID").val(data.Dep_ID);
                               $("#Dep_No").val(data.Dep_No);
                               $("#DeptName").val(data.DeptName);
                               $("#PriorNo").val(data.PriorNo);
                               $("#DeptLevel").val(data.DeptLevel);
                           }
                       },
                       error: function () { }
                   });   // end of ajax                      
               });
               function TreeNode_Click(data) {
                   if (data) {
                       $("#moId").val(data.id);
                       $("#Dep_ID").val(data.id);
                   }
               }
           });
       </script>
}
<div id="container">
    <div id="bmsidebar">
        <div class="title">部门列表</div>
        <div id="ptree">
        </div>
    </div>
    <div id="bmcontent">
        <div id="title" class="title">部门维护</div>
    @using (Html.BeginForm("SaveDepartMent","DepartMent",FormMethod.Post, new { id = "fmEdit" })) {
        @Html.ValidationSummary(true)
        <div id="divdepart" style="text-align:center; width:100%;">
            <table id="tbldepart">
                <tr>
                    <td style="width:120px; text-align:right;">
                        @Html.LabelFor(model => model.Dep_ID)
                    </td>
                    <td style="width:200px; text-align:left;">
                        @Html.TextBoxFor(model => model.Dep_ID, new { @readonly = "true", @style = "background: #b5d6e9;" })
                    </td>
                    <td style="text-align:left;">
                        <a id="btnFind" href="javascript:void(0);" class="button"><span>查看</span></a>                        
                    </td>
                </tr>
                <tr>
                    <td style="width:120px; text-align:right;">
                        @Html.LabelFor(model => model.Dep_No)
                    </td>
                    <td colspan="2" style="width:200px; text-align:left;">
                        @Html.TextBoxFor(model => model.Dep_No)
                        @Html.ValidationMessageFor(model => model.Dep_ID)
                    </td>
                </tr>
                <tr>
                    <td style="width:120px; text-align:right;">
                        @Html.LabelFor(model => model.DeptName)
                    </td>
                    <td colspan="2" style="width:200px; text-align:left;">
                        @Html.TextBoxFor(model => model.DeptName, new { @style="width:300px;"})
                    </td>                    
                </tr>
                <tr>
                    <td style="width:120px; text-align:right;">
                    @Html.LabelFor(model => model.PriorNo)
                    </td>
                    <td colspan="2" style="width:200px; text-align:left;">
                        @Html.DropDownListFor(model => model.PriorNo,
                                       ViewData["PriorNo"] as SelectList,
                                       new { @style = "width:307px; height:22px; font-size:13px;" })
                    </td>
                </tr>
                <tr>
                    <td style="width:120px; text-align:right;">
                        @Html.LabelFor(model => model.DeptLevel)
                    </td>
                    <td colspan="2" style="width:200px; text-align:left;">
                        @Html.TextBoxFor(model => model.DeptLevel)
                    </td>
                </tr>
            </table>
            <div class="buttonpaneld">
                <div style="float: right; margin-right: 10px;">
                    <a id="btnSave" href="javascript:void(0);" class="button"><span>保存</span></a>
                    <a id="btnDel" href="javascript:void(0);" class="button"><span>删除</span></a>
                </div>
            </div>
        </div>
    }

    </div>
    <input type="hidden" id="moId" />
    <input type="hidden" id="hdDicType" />
</div>


